package cn.micai.base.task;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Auther: zhaoxinguo
 * @Date: 2018/7/9 16:33
 * @Description: 每个任务在自己的线程中执行 Web Server为每个请求启动一个新线程
 */
public class ThreadPerTaskWebServer {

    public static void main(String [] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(80);
            while (true) {
                final Socket socket = new Socket();
                Runnable task = new Runnable() {
                    @Override
                    public void run() {
                        handleRequest(socket);
                    }
                };
                new Thread(task).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void handleRequest(Socket socket) {

    }
}
